/******************************************************************************
 * SVN­Versioning-Information:
 * ­­­­­­­­­­­­­­­­­­­­­­­­---------------------
 * $LastChangedRevision: 6 $
 * $LastChangedBy: c.a.duevel $
 * $LastChangedDate: 2009-08-26 15:12:37 +0000 (Wed, 26 Aug 2009) $
 * $HeadURL: http://robofight.googlecode.com/svn/trunk/Server/src/de/hft_stuttgart/botwar/server/model/Chassis.java $
 ******************************************************************************/
package de.hft_stuttgart.botwar.server.model;

import de.hft_stuttgart.botwar.common.models.ChassisInfo;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author pmv-mail@gmx.de,c.a.duevel@gmail.com
 */
@Entity
@Table(name="tblChassis")
public class Chassis implements Serializable {
    @Id
    private String name;
    @Column(nullable=false)
    private int weight;
    @Column(nullable=false)
    private int speed;
    @Column(nullable=false)
    private int cost;
    @Column(nullable=false)
    private int levelRank;
    @OneToMany
    private Collection<RobotConfiguration> robotConfigurations;

    /**
     * This constructor just exists because of the requirements of jpa.
     * Please do not use.
     * @deprecated
     */
    @Deprecated
    public Chassis(){
    }

    /**
     *
     * @param name name of this chassis.
     * @param speed speed of this chassis (in px per s).
     * @param weight maximum weight this chassis can carry.
     * @param cost cost of this chassis.
     * @param levelRank the needed level to use this chassis.
     */
    public Chassis(final String name, final int speed, final int weight,
            final int cost, final int levelRank){
       setName(name);
       setCost(cost);
       setSpeed(speed);
       setWeight(weight);
       setLevelRank(levelRank);
    }

    /**
     * @return The name of this Chassis
     */
    public String getName() {
        return name;
    }
/**
 *
 * @param name The name of this chassis
 */
    public void setName(final String name) {
        if (name==null){
            throw new IllegalArgumentException("Null value is not allowed.");
        }
       this.name = name;
    }
/**
 *
 * @return The cost of this chassis.
 */
    public int getCost() {
        return cost;
    }
/**
 *
 * @return The weight this chassis can carry.
 */
    public int getWeight() {
        return weight;
    }
    /**
     *
     * @return The speed of this chassis.
     */

    public int getSpeed() {
        return speed;
    }

    /**
     * @return All robotconfigurations using this chassis.
     */
    public Collection<RobotConfiguration> getRobots(){
        return robotConfigurations;
    }
    /**
     *
     * @param speed The speed of this chassis.
     */
    public void setSpeed(final int speed){
        if(speed<0){
            throw new IllegalArgumentException("speed must be positive!");
        }
        this.speed=speed;
    }
    /**
     *
     * @param weight The weight of this chassis.
     */
    public void setWeight(final int weight){
        if(weight<0){
            throw new IllegalArgumentException("speed must be positive!");
        }
        this.weight=weight;
    }
    /**
     * @param cost The cost of this chassis.
     */
    public void setCost(final int cost){
        if(cost<0){
            throw new IllegalArgumentException("Cost must be positive!");
        }
        this.cost = cost;
    }
/**
 *
 * @return The rank a player has to have to get this chassis.
 */
    public int getLevelRank(){
        return levelRank;
    }
/**
 *
 * @param levelRank The level a player has to have to get this chassis.
 */
    public void setLevelRank(final int levelRank){
        if (levelRank < 1){
            throw new IllegalArgumentException(
                                        "Levelrank must be greater then zero!");
        }
        this.levelRank = levelRank;
    }
/**
 *
 * @return A ChassisInfo object having all the information of this chassis.
 */
    public ChassisInfo getInfo(){
        return new ChassisInfo(levelRank, weight, speed, cost, name);
    }
}
